/*
 * @Author: taosong 2289713738@qq.com
 * @Date: 2023-12-18 20:46:07
 * @LastEditors: taosong 2289713738@qq.com
 * @LastEditTime: 2023-12-18 21:32:32
 * @FilePath: \ele-h5\src\api\base.ts
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
import axios from 'axios'
import { showDialog } from 'vant'

const instance = axios.create({
  baseURL: '/api'
})

instance.interceptors.response.use((response) => {
  const { data: _data } = response
  const { msg, code, data } = _data
  if (code !== 0) {
    showDialog({
      message: msg
    }).then(() => {
      // 关闭弹窗逻辑
    })
    return Promise.reject(msg)
  }
  return data
})

export default instance
